<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <div id="app">
    <h1>数组变化侦听</h1>

    <button v-on:click="add">btn</button>

    <ul>
      <li v-for="item in arr" :key="item.id">
        姓名是{{item.name}}
      </li>
    </ul>
  </div>

  <script src="../Vue.js"></script>

  <script>
    const { createApp } = Vue;
    

    /*
      push()
      pop()
      shift()
      unshift()
      splice()
      sort()
      reverse()
      以上这些方法都是会改变原数组的

      filter()，concat() 和 slice()等
      是不会改变原数组的
      使用完以后需要进行一次赋值
    */ 
    createApp({
      data() {
        return {
          arr: [
            {
              id: 1,
              name: "zhangsan"
            },
            {
              id: 2,
              name: "lisi"
            },
            {
              id: 3,
              name: "wangwu"
            },
            {
              id: 4,
              name: "zhaoliu"
            }
          ]
        }
      },
      methods: {
        add() {
          // this.arr = this.arr.concat({
          //   id: 5,
          //   name: "sunqi"
          // })
          this.arr = this.arr.map(item => {
            return {
              ...item,
              name: item.name + "❤"
            }
          })
        }
      }
    }).mount("#app")

  </script>
</body>
</html>